#include <bits/stdc++.h>
#define int long long
#define maxn 200010

using namespace std;

int T, ans, n;
int a[maxn];
bool b[maxn];

void dfs(int x) {
    if (x > n) {
        int res = 0;
        for (int i = 1; i <= n; i++) {
            int c = 0;
            for (int j = i - 1; j >= 1; j--) {
                if (b[i] == b[j] && a[i] == a[j]) {
                    c = a[i];
                    break;
                }
            }
            res += c;
        }
        ans = max(ans, res);
        return ;
    }
    b[x + 1] = true;
    dfs(x + 1);
    b[x + 1] = false;
    dfs(x + 1);
}

signed main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> T;
    while (T--) {
        ans = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        dfs(0);
        cout << ans << '\n';
    }
    return 0;
}